/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AddCustomer.java
 *
 * Created on Dec 9, 2011, 2:54:39 PM
 */

package GUI;

import Bussiness.CustomManage;
import DAO.Customer;
import javax.swing.JOptionPane;

/**
 *
 * @author Tung
 */
public class AddCustomer extends javax.swing.JFrame {

    Customer c = null;
    private CustomManage cm = CustomManage.getManager();
    /* create new form AddCustomer */
    public AddCustomer(java.awt.Frame parent, boolean modal) {
       // super(parent, modal);
        initComponents();
    }
    //lay Customer
    public void getCustomer(Customer c) {
        this.c = c;
        this.setTitle("Edit Customer");
        _lblTitle.setText("Edit Customer");
        _txtCustomerName.setText(c.getCustomerName());
       // _cbbClass.setSelectedItem(s.getClassName());
        _txtCustomID.setText(c.getCustomerID());
        _txtAddress.setText(c.getAddress());
        _txtBirthday.setText(c.getBirth());
        _txtPhone.setText(c.getPhoneNumber());
        _txtsotaikhoan.setText(c.getSotaikhoan());
        _txtsothe.setText(c.getSothe());
        _txtmapin.setText(c.getMaPin());
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        _lblTitle = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        _txtCustomerName = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        _txtCustomID = new javax.swing.JTextField();
        _txtBirthday = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        _txtAddress = new javax.swing.JTextArea();
        _txtPhone = new javax.swing.JTextField();
        _txtsotaikhoan = new javax.swing.JTextField();
        _txtsothe = new javax.swing.JTextField();
        _txtmapin = new javax.swing.JTextField();
        _btnSave = new javax.swing.JButton();
        _btnCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        _lblTitle.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        _lblTitle.setText("ADD CUSTOMER MANAGER");

        jLabel2.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
        jLabel2.setText("CustomName");

        _txtCustomerName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _txtCustomerNameActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
        jLabel3.setText("CustomID");

        jLabel4.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
        jLabel4.setText("Address");

        jLabel5.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
        jLabel5.setText("BirthDay");

        jLabel6.setFont(new java.awt.Font("Arial Black", 1, 14)); // NOI18N
        jLabel6.setText("PhoneNumber");

        jLabel7.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        jLabel7.setText("Số Tài Khoản");

        jLabel8.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        jLabel8.setText("Số Thẻ");

        jLabel9.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        jLabel9.setText("Mã Pin");

        _txtCustomID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _txtCustomIDActionPerformed(evt);
            }
        });

        _txtBirthday.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _txtBirthdayActionPerformed(evt);
            }
        });

        _txtAddress.setColumns(20);
        _txtAddress.setRows(5);
        jScrollPane1.setViewportView(_txtAddress);

        _txtPhone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _txtPhoneActionPerformed(evt);
            }
        });

        _btnSave.setText("SAVE");
        _btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnSaveActionPerformed(evt);
            }
        });

        _btnCancel.setText("CANCEL");
        _btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(61, 61, 61)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(4, 4, 4))
                            .addComponent(jLabel5)
                            .addComponent(jLabel6))
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(_txtCustomerName, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(_txtCustomID, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(130, 130, 130)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel7)))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(_txtBirthday, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
                                    .addComponent(_txtPhone, javax.swing.GroupLayout.Alignment.LEADING))
                                .addGap(122, 122, 122)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(_btnSave, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                    .addComponent(jLabel9))))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(37, 37, 37)
                                .addComponent(_btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(26, 26, 26)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(_txtsothe, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                                    .addComponent(_txtmapin, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                                    .addComponent(_txtsotaikhoan, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(275, 275, 275)
                        .addComponent(_lblTitle)))
                .addGap(65, 65, 65))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(_lblTitle)
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(_txtCustomerName, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(_txtsotaikhoan, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel3)
                    .addComponent(_txtsothe, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(_txtCustomID, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(39, 39, 39)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(_txtBirthday, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(_txtmapin, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9))
                        .addGap(23, 23, 23)
                        .addComponent(jLabel4)
                        .addGap(72, 72, 72)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(_btnSave, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(_btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(_txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addGap(101, 101, 101))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void _txtCustomerNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__txtCustomerNameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event__txtCustomerNameActionPerformed

    private void _txtCustomIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__txtCustomIDActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event__txtCustomIDActionPerformed

    private void _txtBirthdayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__txtBirthdayActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event__txtBirthdayActionPerformed

    private void _txtPhoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__txtPhoneActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event__txtPhoneActionPerformed

    private void _btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnCancelActionPerformed

        this.dispose();
    }//GEN-LAST:event__btnCancelActionPerformed

    private void _btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnSaveActionPerformed

        try{
            if(c==null){
                c = new Customer(_txtCustomerName.getText(),_txtCustomID.getText(),_txtAddress.getText(),_txtBirthday.getText(),
                                   _txtPhone.getText(),_txtsotaikhoan.getText(),_txtsothe.getText(),_txtmapin.getText());
                cm.addCustomer(c);
            }else {

                c.setCustomerName(_txtCustomerName.getText());
                c.setCustomerID(_txtCustomID.getText());
                c.setAddress(_txtAddress.getText());
                c.setBirth(_txtBirthday.getText());
                c.setPhoneNumber(_txtPhone.getText());
                c.setSotaikhoan(_txtsotaikhoan.getText());
                c.setSothe(_txtsothe.getText());
                c.setMaPin(_txtmapin.getText());
                cm.updateCustomer(c);
                JOptionPane.showMessageDialog(null, "Update successfull");
            }
            this.dispose();
        }catch(Exception ex){

        }
    }//GEN-LAST:event__btnSaveActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AddCustomer(new javax.swing.JFrame(), true).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton _btnCancel;
    private javax.swing.JButton _btnSave;
    private javax.swing.JLabel _lblTitle;
    private javax.swing.JTextArea _txtAddress;
    private javax.swing.JTextField _txtBirthday;
    private javax.swing.JTextField _txtCustomID;
    private javax.swing.JTextField _txtCustomerName;
    private javax.swing.JTextField _txtPhone;
    private javax.swing.JTextField _txtmapin;
    private javax.swing.JTextField _txtsotaikhoan;
    private javax.swing.JTextField _txtsothe;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
